
<?php
require('../../Connections/KRAPPERCON.php');
$oper = $_POST['oper'];
$field = $_POST['field'];
$cod = '';
$nom = '';
$razsoc = '';
$nif = '';
$dir = '';
$ubigeo = '';
$status = '';

if ($field == '1') {
	$nom = $_POST['t_nompro'];
	$razsoc = $_POST['t_razsoc'];
	$nif = $_POST['t_nifpro'];
	$dir = $_POST['t_dirpro'];
	$ubigeo = $_POST['cb_ubigeo'];
	$status = $_POST['chk_activo'];
	$nomcon = $_POST['t_nomcon'];
	$carcon = $_POST['t_carcon'];
}

if (isset($_POST['t_codprv'])){
$cod = $_POST['t_codprv'];
}
if ($oper == 'save'){
	$tipo_nif = getVal('t_tiponif');
	$pais = getVal('t_codpais');
	$query = "call sp_saveLFA1('".$cod."','".$nom."','".$razsoc."','".$nif."','".$dir."','".$ubigeo."','".$nomcon."','".$carcon."',".$status.",'".$user_now."','".$tipo_nif."','".$pais."')";
	doEcho($query);
	$res = $mysqli->exeQuery($query) ;
	if($res){
		if ( $row = $res->fetch_assoc()) {
			if ($row['newnro'] > 0){ 
			// Muestra el Msg en Javascript y Llena la caja de Texto con el Codigo generado.
				echo "<script>showOk('Se ha creado el Proveedor ".$row['newnro']."'); 
				GEBI('t_codprv').value='".$row['newnro']."';
				noEditProv();</script>";
			}
			else {
				echo "<script>showError('".$row['msg_err']."'); "+
					"</script>";
			}
		}
		$res->close();
	$mysqli->next_result();
	}
}

?>